import java.util.Arrays;

public class MyToString {
    //方法1：直接用Arrays.toString方法激将数组转为字符串
    public static void main1(String[] args) {
        int[] array = {2,4,6,8};
        System.out.println(Arrays.toString(array));
    }



    //方法2：自己创建一个方法去实现将数组转为字符串
    public static String myToString(int[] array){
        if (array == null) {
            return null;
        }
        String ret = "[";
        for (int i = 0; i < array.length; i++) {
            ret += array[i];
            if (i != array.length-1) {
                ret +=  ",";
            }
        }
        ret = ret + "]";
        return ret;
    }

    public static void main(String[] args) {
        int[] array = {1,2,3,4};
        String ret = myToString(array);
        System.out.println(myToString(array));
        System.out.println(myToString(null));
    }
}
